package com.easyfun.healthmagicbox.comm.json;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.easyfun.healthmagicbox.pojo.PersonProfile;

public class PersonProfileJsonWrapper <T extends JsonWrapper> extends
AbstractJsonWrapper<T,PersonProfile> {
	PersonProfile mpp;

	public PersonProfileJsonWrapper(PersonProfile pp)
	{
		mpp = pp;
	}
    public PersonProfileJsonWrapper()  {
    }
 
    
 
    public PersonProfile getMpp() {
		return mpp;
	}
	public void deserializeFromObj(JSONObject obj) throws JSONException {
    	if (mpp == null)
    	{
    		mpp = new PersonProfile();
    	}
    	mpp.setName(obj.getString("name"));
    	if (obj.isNull("age"))
    	{
    		mpp.setAge(Integer.valueOf(0));
    	}else
    		mpp.setAge(obj.getInt("age"));
    	
    	mpp.setAllergy(obj.getString("allergy"));
    	mpp.setDisease(obj.getString("disease"));
    	mpp.setLife(obj.getString("life"));
    	mpp.setEat(obj.getString("eat"));
    	mpp.setIssues(obj.getString("issues"));
    	
    	mpp.setImageFileName(obj.getString("imageFileName"));
        
    	mpp.setPersonID(obj.getString("personID"));
    	mpp.setSharelist(obj.getString("sharelist"));
    	mpp.setInvitedCode(obj.getString("invitedCode"));
    	mpp.setSex(obj.getString("sex"));
    	
    	mpp.setQq(obj.getString("qq"));
    	mpp.setSinaWeiBo(obj.getString("sinaWeiBo"));
    	mpp.setModified(obj.getString("modified"));
    	if (obj.isNull("manualinput"))
    	{
    		mpp.setManualinput(0);
    	}else
    	{
    		mpp.setManualinput(obj.getInt("manualinput"));
    	}
    	
    	if (obj.isNull("birthDay"))
    	{
    		mpp.setBirthDay(1);
    	}else
    	{
    		mpp.setBirthDay(obj.getInt("birthDay"));
    	}
    	
    	if (obj.isNull("birthMonth"))
    	{
    		mpp.setBirthMonth(1);
    	}else
    	{
    		mpp.setBirthMonth(obj.getInt("birthMonth"));
    	}
    	
    	if (obj.isNull("birthYear"))
    	{
    		mpp.setBirthYear(1);
    	}else
    	{
    		mpp.setBirthYear(obj.getInt("birthYear"));
    	}
    	
    	if (obj.isNull("weigth"))
    	{
    		mpp.setWeigth(Double.valueOf(0));
    	}else
    		mpp.setWeigth(obj.getDouble("weigth"));
    	
    	if (obj.isNull("heigth"))
    	{
    		mpp.setHeigth(Double.valueOf(0));
    	}else
    		mpp.setHeigth(obj.getDouble("heigth"));
    }
 
 
    public JSONObject serializeToObj() throws JSONException {
        JSONObject serializedObj = new JSONObject();
        serializedObj.put("name", mpp.getName());
        serializedObj.put("age", mpp.getAge());
        serializedObj.put("heigth", mpp.getHeigth());
        serializedObj.put("imageFileName", mpp.getImageFileName());
        serializedObj.put("personID", mpp.getPersonID());
        serializedObj.put("qq", mpp.getQq());
        serializedObj.put("sex", mpp.getSex());
        serializedObj.put("sinaWeiBo", mpp.getSinaWeiBo());
        serializedObj.put("weigth", mpp.getWeigth());
        serializedObj.put("birthDay", mpp.getBirthDay());
        serializedObj.put("birthYear", mpp.getBirthYear());
        serializedObj.put("birthMonth", mpp.getBirthMonth());
        serializedObj.put("allergy", mpp.getAllergy());
        serializedObj.put("disease", mpp.getDisease());
        serializedObj.put("life", mpp.getLife());
        serializedObj.put("eat", mpp.getEat());
        serializedObj.put("issues", mpp.getIssues());
        serializedObj.put("sharelist", mpp.getSharelist());
        serializedObj.put("invitedCode", mpp.getInvitedCode());

        serializedObj.put("manualinput", mpp.getManualinput());
        serializedObj.put("modified", mpp.getModified());
        return serializedObj;
    }
    
}
